<?php
class UpdownWidget extends HomeAction
{

		public function render($data){

			//缓存KEY
			$key=md5($data['typeid'].'up'.$_GET['id']);

			if(F($key)){
				
				$list=explode('*****',F($key));
				$this->assign('up',$list[0]);
				$this->assign('down',$list[1]);

			}else{

				//打开表
				$article=M('Article');	
				$menu=M('Menu');

				//查询条件
				$where['id']=array('LT',$_GET['id']);
				$where['typeid']=$data['typeid'];

				//获得上一篇内容数据
				$up=$article->where($where)->order('id desc')->find();
				if($up){
					$res=$menu->where('typeid='.$data['typeid'])->field('contenturl')->find();
					$up['url']=U($res['contenturl'].$up['id']);
					$up='<a href="'.$up['url'].'">'.$up['title'].'</a>';
				}else{
					$up='没有了';
				}	

				//查询条件
				$where['id']=array('GT',$_GET['id']);
				$where['typeid']=$data['typeid'];
				//获得下一篇数据
				$down=$article->where($where)->order('id asc')->find();

				if($down){
					$res=$menu->where('typeid='.$data['typeid'])->field('contenturl')->find();
					$down['url']=U($res['contenturl'].$down['id']);
					$down='<a href="'.$down['url'].'">'.$down['title'].'</a>';
				}else{
					$down='没有了';
				}	


				F($key,$up.'*****'.$down);
				$this->assign('up',$up);
				$this->assign('down',$down);

			}

			$this->display(dirname(__FILE__).'/Updown.html');

		}




}